package com.wwl.collection.job.job1;

import java.io.Serializable;

public class Person implements Serializable,Comparable<Person> {
    private String name;
    private int height;

    public Person() {
    }

    public Person(String name, int height) {
        this.name = name;
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", height=" + height +
                '}';
    }

    @Override
    public int compareTo(Person o) {
        int diff = (int) (this.height-o.height);
        if(diff == 0){
            return this.name.compareTo(o.name);
        }
        return diff;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        //Person.class
        if (o == null || getClass() != o.getClass()) return false;

        Person person = (Person) o;

        return height == person.height;
    }

    @Override
    public int hashCode() {
        return height;
    }
}

